package com.xxzx.publicprevention.config;

import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;


/**
 * @author ChengJianSheng
 * @date 2019-03-03
 */
@EnableOAuth2Sso
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers(
                "/**/*.jpg",
                "/**/*.gif",
                "/**/*.png",
                "/**/*.css",
                "/**/*.js",
                "/**/*.swf",
                "/**/*.eot",
                "/**/*.woff2",
                "/**/*.ttf",
                "/**/*.woff");
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers(
                        "/geoZhyfq/**"
                        , "/geoZhyhd/**"
                        , "/recordDO/**"
                        , "/upload/**"
                        , "/user/**"

                ).permitAll()
                .anyRequest().authenticated()
                .and().headers().frameOptions().disable() //允许网页被Frame
                .and().csrf().disable()//允许跨域
        ;
        http
                .logout()
                .logoutSuccessUrl("http://116.8.3.172:8091/server/oauth/exit");
    }
}

